package com.purchase.order.controller;

import com.purchase.common.annotation.Log;
import com.purchase.common.core.controller.BaseController;
import com.purchase.common.core.domain.AjaxResult;
import com.purchase.common.core.page.TableDataInfo;
import com.purchase.common.enums.BusinessType;
import com.purchase.order.domain.MaterialType;
import com.purchase.order.service.IMaterialService;
import org.aspectj.weaver.loadtime.Aj;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@RequestMapping("/material")
public class MaterialController extends BaseController {

    @Autowired
    IMaterialService materialService;

    @PreAuthorize("@ss.hasPermi('purchase:purchase:insert')")
    @Log(title = "物资种类添加", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult addMaterial(String name){
        materialService.addMaterial(name);
        return success();
    }

    @PreAuthorize("@ss.hasPermi('purchase:purchase:insert')")
    @Log(title = "物资种类修改", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult putMaterial(String id,String name){
        materialService.putMaterial(id,name);
        return success();
    }

    @PreAuthorize("@ss.hasPermi('purchase:purchase:insert')")
    @Log(title = "物资种类删除", businessType = BusinessType.DELETE)
    @DeleteMapping
    public AjaxResult deleteMaterial(String id){
        materialService.deleteMaterial(id);
        return success();
    }

//    @PreAuthorize("@ss.hasPermi('purchase:purchase:insert')")
//    @Log(title = "物资种类列表", businessType = BusinessType.SELECT)
    @PostMapping("/list")
    public TableDataInfo getMaterial(String materialTypeName){
        startPage();
        List<MaterialType> list = materialService.getMaterial(materialTypeName);
        return getDataTable(list);
    }

    @GetMapping("/allList")
    public List<MaterialType> getAll(){
        return materialService.getAll();
    }
}
